import com.zyl.common.SparkTools
import org.apache.spark.sql.{SaveMode, SparkSession}

object DimUsertagMskM extends SparkTools{
  override def run(spark: SparkSession): Unit = {

    import spark.implicits._
    import org.apache.spark.sql.functions._

    spark.table(ODS_USERTAG_TABLE_NAME)
      .where($"month_id"===month_id)
      .select(
        md5($"mdn") as "mdn",
        md5($"name") as "name",
        $"gender",
        $"age",
        md5($"id_number") as "id_number",
        $"number_attr",
        $"trmnl_brand",
        $"trmnl_price",
        $"packg",
        $"conpot",
        $"resi_grid_id",
        $"resi_county_id"
      ).write
      .format("csv")
      .option("sep","\t")
      .mode(SaveMode.Overwrite)
      .save(s"${DIM_USERTAG_PATH}month_id="+month_id)


    spark.sql(
      s"""
        |alter table $DIM_USERTAG_TABLE_NAME add if not exists partition(month_id=$month_id)
      """.stripMargin)


  }
}
